"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
const fs = __importStar(require("fs"));
const vue_1 = require("vue");
const component = {
    template: fs.readFileSync(`${__dirname}/role_dialog.html`, "utf-8"),
    props: {
        roleBoxPos: Boolean,
        nodeData: Object || String,
        treeData: Object || String,
    },
    emits: ['sureRolePic', 'closeRolePanel'],
    data() {
        return {
            input: (0, vue_1.ref)(''),
            isPop: (0, vue_1.ref)(false),
            isSelect: false,
            selectRole: '',
            selectLocation: '',
            defaultProps: {
                children: 'children',
                label: 'label',
            },
        };
    },
    methods: {
        handleNodeClick(data) {
            console.log("data", data);
            if (data.type == "character") {
                this.$data.selectRole = data.info;
                this.$data.isSelect = true;
            }
            else if (data.type == "location") {
                this.$data.selectLocation = data.info;
                this.$data.isSelect = true;
            }
            else {
                this.$data.selectRole = "";
                this.$data.selectLocation = "";
                this.$data.isSelect = false;
            }
        },
        filterRole() {
            let rolechildren = "";
            if (this.$data.input != "") {
                rolechildren = this.searchKeywords(this.$data.input);
            }
            else {
                rolechildren = this.filterChildrenByLabel(this.$props.treeData, "角色库");
            }
            console.log("rolechildren", rolechildren);
            const rolelist = [{
                    label: '当前项目',
                    children: [
                        {
                            label: '角色库',
                            children: rolechildren,
                        }
                    ]
                }];
            console.log("rolelist", rolelist);
            return rolelist;
        },
        searchKeywords(keyword) {
            const rolechildren = this.filterChildrenByLabel(this.$props.treeData, "角色库");
            // 使用 filter 方法过滤匹配关键词的数据
            const filteredRoleChildren = rolechildren.filter(child => {
                return child.label.includes(keyword);
            });
            return filteredRoleChildren;
        },
        filterChildrenByLabel(tree, targetLabel) {
            for (const node of tree) {
                if (node.label === targetLabel) {
                    return node.children || [];
                }
                else if (node.children) {
                    const filteredChildren = this.filterChildrenByLabel(node.children, targetLabel);
                    if (filteredChildren.length > 0) {
                        return filteredChildren;
                    }
                }
            }
            return [];
        },
        //确认角色图片
        sureRolePic() {
            this.$emit('sureRolePic', this.$data.selectRole);
        },
        closeRolePanel() {
            this.$emit('closeRolePanel');
        },
    },
    watch: {},
    created() { },
    computed: {
        shouldDisplayImage() {
            var _a, _b;
            const role = (_b = (_a = this.nodeData) === null || _a === void 0 ? void 0 : _a.properties) === null || _b === void 0 ? void 0 : _b.role;
            return (role === null || role === void 0 ? void 0 : role.role_picUrl) && this.isSelect === false;
        },
        filterAndStructure() {
            console.log("666");
            let rolechildren = "";
            if (this.$data.input != "") {
                rolechildren = this.searchKeywords(this.$data.input);
            }
            else {
                console.log("this.$props.treeData", this.$props.treeData);
                rolechildren = this.filterChildrenByLabel(this.$props.treeData, "角色库");
            }
            console.log("rolechildren", rolechildren);
            const rolelist = [{
                    label: '当前项目',
                    children: [
                        {
                            label: '角色库',
                            children: rolechildren,
                        }
                    ]
                }];
            console.log("rolelist", rolelist);
            return rolelist;
        }
    },
    mounted() {
        // 加载 css
        // lib_css.load([
        // 	{
        // 	  parent: this.$el,
        // 	  url_s: path.join(`${__dirname}/role_dialog.css`),
        // 	},
        //   ]);
    },
};
module.exports = component;
